package com.alibaba.cloud.ai.example.flight.controller;


import com.alibaba.cloud.ai.example.flight.model.Flight;
import com.alibaba.cloud.ai.example.flight.model.command.FlightCommand;
import com.alibaba.cloud.ai.example.flight.model.query.FlightQuery;
import com.alibaba.cloud.ai.example.flight.service.FlightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/flights")
public class FlightController {
    @Autowired
    private FlightService flightService;

    @GetMapping("/list")
    public List<Flight> getFlights() {
        return flightService.queryFilghtList();
    }

    @GetMapping("/detail1")
    public Flight getFlight1(@RequestParam("name") String name, @RequestParam("orderId") Integer orderId) {
        return flightService.queryFlight(name, orderId);
    }

    @PostMapping("/detail2")
    public Flight getFlight2(@RequestBody FlightQuery query) {
        return flightService.queryFlight(query);
    }

    @PostMapping("/add")
    public String addFlight(@RequestBody FlightCommand command) {
        flightService.addFlight(command);
        return "success";
    }
}